package com.wbao.dianniu.ui;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.R;
import com.wbao.dianniu.adapter.AmDetailAdapter;
import com.wbao.dianniu.adapter.NoScrollGridAdapter;
import com.wbao.dianniu.customView.MyListView;
import com.wbao.dianniu.data.QaResponse;
import com.wbao.dianniu.data.QuestAnswerCountsData;
import com.wbao.dianniu.data.QuestAnswerListData;
import com.wbao.dianniu.listener.IAnswerDeleteListener;
import com.wbao.dianniu.listener.IPraiseListener;
import com.wbao.dianniu.listener.IQuestAnswerListListener;
import com.wbao.dianniu.listener.IQuestAnswerListener;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.manager.AmDataChangeManager;
import com.wbao.dianniu.manager.AnswerDeleteManger;
import com.wbao.dianniu.manager.BrowseAddManger;
import com.wbao.dianniu.manager.PraiseManger;
import com.wbao.dianniu.manager.QAnswerListManger;
import com.wbao.dianniu.manager.QuestAnswerManager;
import com.wbao.dianniu.scrollview.PullToRefreshView;
import com.wbao.dianniu.scrollview.PullToRefreshView.OnFooterRefreshListener;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.utils.PictureDownloadUtils;
import com.wbao.dianniu.utils.Utils;

/**
 * 匿名详情页
 * 
 * @author yejianjun
 * 
 */
public class AmDetailActivity extends Activity implements IQuestAnswerListListener, IQuestAnswerListener, IPraiseListener,
		IAnswerDeleteListener,OnFooterRefreshListener,OnClickListener {

	private LinearLayout waittingLayout;
	private ProgressBar waittingProBar;
	private TextView waittingTV;

	/** 标题左侧的返回皱键 */
	private ImageButton backBtn;
	/** 标题 */
	private TextView titleTV;
	/** 内容 */
	public TextView contentTV;
	/** 转发数 */
	public TextView forwardTV;
	/** 点赞数 */
	public TextView goodTV;
	/** 回复数 */
	public TextView answerTV;
	private int isGoodFlag;
	private int goodCount = 0;
	private int answerCount = 0;
	private int accountId;
	private int questId;
	private AmDetailAdapter adapter;
	private QAnswerListManger manager;
	/** 回答列表listview */
	private MyListView myListView;
	/** 点赞图标 */
	private TextView goodFlag;
	private EditText commentEditText;
	private Button applyBtn;
	private ImageButton emjobImage;
	private Dialog dialog;
	/** 点赞按钮 */
	private LinearLayout praiseLayout;
	private GridView mGridView;
	private TextView aliasNameTV;
	private List<QuestAnswerListData> mList = new ArrayList<QuestAnswerListData>();
	private AnswerDeleteManger deleteManager;
	private ScrollView mScrollView;
	private final int PAGE_COUNTS = 10;
	private int currentPage = 0;
	private PullToRefreshView mPullToRefreshView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 系统版本大于19
			Utils.setTranslucentStatus(this,true);
			SystemBarTintManager tintManager = new SystemBarTintManager(this);
			tintManager.setStatusBarTintEnabled(true);
			tintManager.setStatusBarTintResource(R.color.title_bg);// 通知栏所需颜色
		}
		setContentView(R.layout.activity_am_detail);
		initWattingView();
		initBaseView();
		initView();
		initData();
		requestData(currentPage);
	}

	private void initWattingView() {
		waittingLayout = (LinearLayout) findViewById(R.id.waitting_layout);
		waittingProBar = (ProgressBar) findViewById(R.id.waitting_progress);
		waittingTV = (TextView) findViewById(R.id.waitting_text_desc);
	}

	private void initData(){
		BrowseAddManger browseManager = new BrowseAddManger(this);
		browseManager.browseAdd(GlobalContext.accountId, questId);
		manager = new QAnswerListManger(this);
		manager.addListener(this);
		deleteManager = new AnswerDeleteManger(this);
		deleteManager.addAnswerDeleteListener(this);
		adapter = new AmDetailAdapter(this);
		adapter.addData(mList,new QuestAnswerCountsData());
		myListView.setAdapter(adapter);
		myListView.setOnItemLongClickListener(onItemLongClick);
		setListViewHeightBasedOnChildren(myListView);
	}
	
	private void requestData(int page) {
		manager.requestAnswerList(GlobalContext.accountId, String.valueOf(questId), page * PAGE_COUNTS,PAGE_COUNTS);
	}
	
	private void initView(){
		myListView = (MyListView) findViewById(R.id.am_detail_list);
		
		mPullToRefreshView.setOnFooterRefreshListener(this);
		mPullToRefreshView.setLastUpdated(new Date().toLocaleString());
	}

	private void initBaseView() {
		backBtn = (ImageButton) findViewById(R.id.back_button);
		backBtn.setOnClickListener(this);
		titleTV = (TextView) findViewById(R.id.title);
		titleTV.setText("查看匿名");
		
		mPullToRefreshView = (PullToRefreshView) findViewById(R.id.am_pull_to_refresh_view);
		mScrollView = (ScrollView) findViewById(R.id.am_scrollview);
		aliasNameTV = (TextView) findViewById(R.id.am_alias_name);
		contentTV = (TextView) findViewById(R.id.am_content_tv);
		forwardTV = (TextView) findViewById(R.id.am_detail_forward_tv);
		goodTV = (TextView) findViewById(R.id.am_detail_praise_tv);
		answerTV = (TextView) findViewById(R.id.am_detail_response_tv);
		goodFlag = (TextView) findViewById(R.id.am_praise_iv);
		praiseLayout = (LinearLayout) findViewById(R.id.am_detail_praiseLayout);
		praiseLayout.setOnClickListener(this);
		mGridView = (GridView) findViewById(R.id.am_detail_gridview);

		Intent intent = getIntent();
		QaResponse resp = new QaResponse();
		Bundle bundle = intent.getBundleExtra(GlobalContext.AM_DATA_BUNDLE);
		if (null != bundle) {
			resp.realName = bundle.getString(GlobalContext.BUNDLE_REALNAME);
			resp.content = bundle.getString(GlobalContext.BUNDLE_CONTENT);
			resp.visitorCount = bundle.getInt(GlobalContext.BUNDLE_VISITORCOUNT);
			resp.forwardCount = bundle.getInt(GlobalContext.BUNDLE_FORWARDCOUNT);
			resp.questImgs = bundle.getString(GlobalContext.BUNDLE_QUESTIMGS);
			goodCount = bundle.getInt(GlobalContext.BUNDLE_GOODCOUNT);
			answerCount = bundle.getInt(GlobalContext.BUNDLE_ANSWERCOUNT);
			isGoodFlag = bundle.getInt(GlobalContext.BUNDLE_ISGOOD);
			accountId = bundle.getInt(GlobalContext.BUNDLE_ACCOUNTID);
			questId = bundle.getInt(GlobalContext.BUNDLE_QUESTID);
		}
		praiseChanged(isGoodFlag, goodCount);
		if(TextUtils.isEmpty(resp.realName)){
			aliasNameTV.setVisibility(View.GONE);
		}else{
			aliasNameTV.setVisibility(View.VISIBLE);
			aliasNameTV.setText(resp.realName == null ? "" : "匿名者：" + resp.realName);
		}
		contentTV.setMovementMethod(LinkMovementMethod.getInstance());
		contentTV.setAutoLinkMask(Linkify.WEB_URLS); 
		contentTV.setText(resp.content == null ? "" : resp.content);
		contentTV.setOnLongClickListener(longClickListener);
		Utils.showPriseCounts(resp.forwardCount, forwardTV);
		Utils.showPriseCounts(answerCount, answerTV);
		if (TextUtils.isEmpty(resp.questImgs)) {
			mGridView.setVisibility(View.GONE);
		} else {
			mGridView.setVisibility(View.VISIBLE);
			ArrayList<String> imageUrls = PictureDownloadUtils.getInstance().stringToList(resp.questImgs);
			double multiple = Math.ceil((float)imageUrls.size()/GlobalContext.NUMCOLUMNS);
	    	int height = (int) (Utils.dip2px(this, 80) * multiple + (multiple -1) * Utils.dip2px(this, 10));
	    	int width = 0;
	    	if(multiple >= 1){
	    		width = Utils.dip2px(this, 80) * GlobalContext.NUMCOLUMNS + (GlobalContext.NUMCOLUMNS -1) * Utils.dip2px(this, 5);
	    	}else{
	    		width = Utils.dip2px(this, 80) * imageUrls.size() + (imageUrls.size()  -1) * Utils.dip2px(this, 5);
	    	}
	    	width = width + Utils.dip2px(this, 10);// 加上pendingLeft 10dp
			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width,height);
			mGridView.setLayoutParams(lp);
			mGridView.setAdapter(new NoScrollGridAdapter(this, imageUrls));
			// 点击回帖九宫格，查看大图
			mGridView.setOnItemClickListener(new MyItemClickListener(imageUrls));
		}

		commentEditText = (EditText) findViewById(R.id.am_comment_content);
		commentEditText.setOnEditorActionListener(actionListener);
		applyBtn = (Button) findViewById(R.id.am_reply);
		emjobImage = (ImageButton) findViewById(R.id.am_emjob);
		applyBtn.setOnClickListener(this);
		emjobImage.setOnClickListener(this);

	}

	// 上拉刷新数据请求
	private void pullUpRequest(){
		//没有搜索结果 或者数据为空 上拉没有效果
		currentPage ++;
		requestData(currentPage);
	}
	
	OnEditorActionListener actionListener = new OnEditorActionListener() {

		@Override
		public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
			if (actionId==EditorInfo.IME_ACTION_SEND /*||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER)*/) {    
				String comment = commentEditText.getText().toString().trim();
				if (null == comment || "".equals(comment)) {
					Notification.toast(AmDetailActivity.this, "请输入你的评论!");
					return false;
				}
				QuestAnswerManager qaManager = new QuestAnswerManager(AmDetailActivity.this);
				qaManager.addQuestAnswerListener(AmDetailActivity.this);
				qaManager.addResponse(GlobalContext.accountId, questId, comment);
				// 隐藏键盘
				Utils.hideSoftInput(AmDetailActivity.this, commentEditText);
				return true;
	           } 
			return false;
		}
	};

	class MyItemClickListener implements OnItemClickListener {

		private ArrayList<String> url;

		public MyItemClickListener(ArrayList<String> url) {
			this.url = url;
		}

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			// 弹出图片查看按钮
			imageBrower(position, url);
		}
	}

	/**
	 * 打开图片查看器
	 * 
	 * @param position
	 * @param urls2
	 */
	protected void imageBrower(int position, ArrayList<String> urls2) {
		Utils.imageBrower(this, position, urls2);
	}

	private void updateCounts(QuestAnswerCountsData qacd) {
		if (null != qacd) {
			goodCount = qacd.goodCount;
			answerCount = qacd.answerCount;
			Utils.showPriseCounts(qacd.forwardCount, forwardTV);
			Utils.showPriseCounts(goodCount, goodTV);
			Utils.showPriseCounts(answerCount, answerTV);
		}
	}

	private void praiseChanged(int falg, int counts) {
		if (1 == falg) {
			goodFlag.setText("已赞");
			goodFlag.setTextColor(getResources().getColor(R.color.red));
		} else {
			goodFlag.setText("赞");
			goodFlag.setTextColor(getResources().getColor(R.color.edit_hint_color));
		}
		Utils.showPriseCounts(counts, goodTV);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_button:
			finish();
			break;
		case R.id.am_detail_praiseLayout:
			if (0 == isGoodFlag) {
				isGoodFlag = 1;
				goodCount++;
			} else {
				isGoodFlag = 0;
				goodCount--;
			}
			praiseChanged(isGoodFlag, goodCount);
			AmDataChangeManager.getInstance().priseNotify(questId, isGoodFlag, goodCount);
			// 请求点赞接口
			PraiseManger praiseManger = new PraiseManger(this);
			praiseManger.addPraiseListener(AmDetailActivity.this);
			praiseManger.praise(GlobalContext.accountId, questId);
			// 判断以前点赞状态
			break;
		case R.id.right_imagebutton:
			showRealase();
			break;
		case R.id.custom_qa_btn:
			if (null != dialog && dialog.isShowing()) {
				dialog.dismiss();
			}
			if (checkLevel()) {
				Intent ask = new Intent();
				ask.setClass(AmDetailActivity.this, AskActivity.class);
				startActivity(ask);
			} else {
				showAuthLevel("您还未完成认证，请先认证！");
			}
			break;
		case R.id.custom_am_btn:
			Intent anonymous = new Intent();
			anonymous.setClass(AmDetailActivity.this, AmQuestionActivity.class);
			startActivity(anonymous);
			if (null != dialog && dialog.isShowing()) {
				dialog.dismiss();
			}
			break;
		case R.id.close_Dialog:
			if (null != dialog && dialog.isShowing()) {
				dialog.dismiss();
			}
			break;
		case R.id.am_reply:
			String comment = commentEditText.getText().toString().trim();
			if (null == comment || "".equals(comment)) {
				Notification.toast(AmDetailActivity.this, "请输入你的评论!");
				return;
			}
			QuestAnswerManager qaManager = new QuestAnswerManager(AmDetailActivity.this);
			qaManager.addQuestAnswerListener(this);
			qaManager.addResponse(GlobalContext.accountId, questId, comment);
			// 隐藏键盘
			Utils.hideSoftInput(AmDetailActivity.this, commentEditText);
			break;
		default:
			break;
		}

	}

	public boolean checkLevel() {
		boolean ret = false;
		if (GlobalContext.isPerfectData) {
			// 提示用户完成认证 必须达到一级认证才能提问
			ret = true;
		}
		return ret;
	}

	/**
	 * 显示弹出框
	 */
	private void showRealase() {
		dialog = new Dialog(this, R.style.custom_Dialog);
		Window win = dialog.getWindow();
		win.getDecorView().setPadding(3, 3, 3, 3);
		win.setGravity(Gravity.CENTER);
		WindowManager.LayoutParams lp = win.getAttributes();
		lp.width = WindowManager.LayoutParams.MATCH_PARENT;
		lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
		lp.x = 0;
		lp.y = -200;
		win.setAttributes(lp);
		View view = LayoutInflater.from(this).inflate(R.layout.custom_release_dialog, null);
		Button qaButton = (Button) view.findViewById(R.id.custom_qa_btn);
		Button amButton = (Button) view.findViewById(R.id.custom_am_btn);
		ImageView closeButton = (ImageView) view.findViewById(R.id.close_Dialog);
		dialog.setContentView(view);
		dialog.setCancelable(true);
		dialog.show();
		qaButton.setOnClickListener(this);
		amButton.setOnClickListener(this);
		closeButton.setOnClickListener(this);
	}

	/**
	 * 显示认证弹出框
	 */
	private void showAuthLevel(String msg) {
		dialog = new Dialog(this, R.style.custom_Dialog);
		Window win = dialog.getWindow();
		win.getDecorView().setPadding(3, 3, 3, 3);
		win.setGravity(Gravity.CENTER);
		View view = LayoutInflater.from(this).inflate(R.layout.custom_message_dialog, null);
		Button okBtn = (Button) view.findViewById(R.id.custom_msg_ok);
		Button cancelBtn = (Button) view.findViewById(R.id.custom_msg_cancel);
		TextView message = (TextView) view.findViewById(R.id.custom_msg_message);
		message.setText(msg);
		dialog.setContentView(view);
		dialog.setCancelable(true);
		dialog.show();
		okBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (null != dialog && dialog.isShowing()) {
					dialog.dismiss();
				}
				// 跳转到认证界面
				Intent intent = new Intent();
				intent.setClass(AmDetailActivity.this,PerfectInfoActivity.class);
				startActivity(intent);
			}
		});
		cancelBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (null != dialog && dialog.isShowing()) {
					dialog.dismiss();
				}
			}
		});
	}

	@Override
	public void onPraiseFailure(int errorCode, String errorMsg) {

	}

	@Override
	public void onPraiseSuccess() {

	}

	@Override
	public void onQuestAnswerFailure(int errorCode, String errorMsg) {
		// ErrorMsgHandler.getInstance().onErrorMsg(this, errorCode, errorMsg);
		
	}

	@Override
	public void onQuestAnswerSuccess(QuestAnswerListData qacd) {
		// TODO Auto-generated method stub
		// 评论完成 添加一条记录到回复列表
		if (null != qacd) {
			commentEditText.setText("");
			qacd.accountId = GlobalContext.accountId;
			qacd.goodCount = 0;
			adapter.addOneData(qacd);
			adapter.notifyDataSetChanged();
			// 添加一条回答数
			answerCount++;
			Utils.showPriseCounts(answerCount, answerTV);
			// 通知界面更新回答列表
			AmDataChangeManager.getInstance().replyNotify(questId, answerCount);
			mScrollView.fullScroll(ScrollView.FOCUS_UP);
			setListViewHeightBasedOnChildren(myListView);
//			new Handler().post(new Runnable() {
//				@Override
//				public void run() {
//				}
//			});
		}
	}

	@Override
	public void onFailure(int errorCode, String errorMsg) {
		waittingLayout.setVisibility(View.VISIBLE);
		waittingProBar.setVisibility(View.GONE);
		waittingTV.setText("加载失败，请稍后再试...");
		mPullToRefreshView.onFooterRefreshComplete();
		// ErrorMsgHandler.getInstance().onErrorMsg(this, errorCode, errorMsg);
	}

	@Override
	public void onSuccess(List<QuestAnswerListData> objdata, QuestAnswerCountsData qacd) {
		waittingLayout.setVisibility(View.GONE);
		mPullToRefreshView.onFooterRefreshComplete();
		if (null != objdata) {
			adapter.addData(objdata, qacd);
			mList = adapter.getList();
			adapter.notifyDataSetChanged();
			setListViewHeightBasedOnChildren(myListView);
			updateCounts(qacd);
		}
	}

	OnItemLongClickListener onItemLongClick = new OnItemLongClickListener() {

		@Override
		public boolean onItemLongClick(AdapterView<?> parent, View view,
				int position, long id) {
			showDeleteDialog(position,(QuestAnswerListData)adapter.getItem(position));
			return true;
		}
	};

	/**
	 * 显示收藏取消弹出框
	 */
	private void showDeleteDialog(final int position,final QuestAnswerListData answerData) {
		dialog = new Dialog(this, R.style.custom_Dialog);
		Window win = dialog.getWindow();
		win.getDecorView().setPadding(3, 3, 3, 3);
		win.setGravity(Gravity.BOTTOM);
		View view = LayoutInflater.from(this).inflate(R.layout.qa_delete_dialog, null);
		Button copyBtn = (Button) view.findViewById(R.id.qa_copy_button);
		Button deleteBtn = (Button) view.findViewById(R.id.qa_delete_button);
		Button cancelBtn = (Button) view.findViewById(R.id.qa_delete_cancel);
		if (answerData.accountId == GlobalContext.accountId || accountId == GlobalContext.accountId) {
			deleteBtn.setVisibility(View.VISIBLE);
		} else {
			deleteBtn.setVisibility(View.GONE);
		}
		// 复制
		copyBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (null != dialog && dialog.isShowing()) {
					dialog.dismiss();
				}
				ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
				cmb.setText(answerData.content);
			}
		});
		// 删除
		deleteBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (null != dialog && dialog.isShowing()) {
					dialog.dismiss();
				}
				deleteManager.delete(answerData.id);
				adapter.deleteOneData(position);
				// 删除后，回复数减一
				answerCount--;
				Utils.showPriseCounts(answerCount, answerTV);
				AmDataChangeManager.getInstance().replyNotify(questId, answerCount);
			}
		});
		// 取消
		cancelBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (null != dialog && dialog.isShowing()) {
					dialog.dismiss();
				}
			}
		});
		dialog.setContentView(view);
		dialog.setCancelable(true);
		dialog.show();
	}

	@Override
	public void onAnswerDeleteFailure(int errorCode, String errorMsg) {
	}

	@Override
	public void onAnswerDeleteSuccess() {
	}

	OnLongClickListener longClickListener = new OnLongClickListener() {

		@Override
		public boolean onLongClick(View v) {
			showCopyDialog();
			return true;
		}
	};
	
	/**
	 * 显示收藏取消弹出框
	 */
	private void showCopyDialog() {
		dialog = new Dialog(this, R.style.custom_Dialog);
		Window win = dialog.getWindow();
		win.getDecorView().setPadding(3, 3, 3, 3);
		win.setGravity(Gravity.BOTTOM);
		View view = LayoutInflater.from(this).inflate(R.layout.qa_collection_dialog, null);
		Button collectBtn = (Button) view.findViewById(R.id.qa_collection_button);
		Button cancelBtn = (Button) view.findViewById(R.id.qa_collection_cancel);
		collectBtn.setText("复制");
		// 复制
		collectBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(null != dialog && dialog.isShowing()){
					dialog.dismiss();
				}
				ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 
				cmb.setText(contentTV.getText().toString().trim());
			}
		});
		// 取消
		cancelBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(null != dialog && dialog.isShowing()){
					dialog.dismiss();
				}
			}
		});
		dialog.setContentView(view);
		dialog.setCancelable(true);
		dialog.show();
	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
		
	public void setListViewHeightBasedOnChildren(ListView listView) {
		// 获取ListView对应的Adapter
		int totalHeight = 0;
		for (int i = 0, len = adapter.getCount(); i < len; i++) {
			// listAdapter.getCount()返回数据项的数目
			View listItem = adapter.getView(i, null, listView);
			// 计算子项View 的宽高
			listItem.measure(0, 0);
			// 统计所有子项的总高度
			totalHeight += listItem.getMeasuredHeight();
		}

		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
		// listView.getDividerHeight()获取子项间分隔符占用的高度
		// params.height最后得到整个ListView完整显示需要的高度
		listView.setLayoutParams(params);
	}

	/* (non-Javadoc)		上拉刷新...
	 * @see com.wbao.dianniu.scrollview.PullToRefreshView.OnFooterRefreshListener#onFooterRefresh(com.wbao.dianniu.scrollview.PullToRefreshView)
	 */
	@Override
	public void onFooterRefresh(PullToRefreshView view) {
		// TODO Auto-generated method stub
		pullUpRequest();
	}
		
}
